home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir30 / heaven_1.zip / DDTE.LSP < prev    next >
Lisp/Scheme  |  1993-11-01  |  8KB  |  295 lines

  1. ;;╔══════════════════════════════════════════════════════════════════════════╗
  2. ;;║Program name:       DDTE.LSP                                              ║
  3. ;;║Initial Author:     Michael Jenkins                                       ║
  4. ;;║Description:        This is a dialog box for editing multiple lines of    ║
  5. ;;║                    text. The selections will automatically be filtered.  ║
  6. ;;║                    Pressing <Enter> will automatically bring up the next ║
  7. ;;║                    piece of text if it's not the last piece, otherwise it║
  8. ;;║                    exits the dialog and updates the pieces of text.      ║
  9. ;;╚══════════════════════════════════════════════════════════════════════════╝
  10.  
  11.  
  12. ;;; ===================== load-time error checking ============================
  13. ;;;
  14.  
  15. (defun ai_abort (app msg)
  16.    (defun *error* (s)
  17.       (if old_error (setq *error* old_error))
  18.       (princ)
  19.    )
  20.    (if msg
  21.       (alert (strcat " Application error: "
  22.             app
  23.             " \n\n  "
  24.             msg
  25.             "  \n"
  26.          )
  27.       )
  28.    )
  29.    (exit)
  30. )
  31.  
  32. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  33. ;;; and then try to load it.
  34. ;;;
  35. ;;; If it can't be found or it can't be loaded, then abort the
  36. ;;; loading of this file immediately, preserving the (autoload)
  37. ;;; stub function.
  38.  
  39. (cond
  40.    (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  41.  
  42.    (  (not (findfile "ai_utils.lsp"))                     ; find it
  43.       (ai_abort "DDTE"
  44.          (strcat "Can't locate file AI_UTILS.LSP."
  45.    "\n Check support directory.")))
  46.  
  47.    (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  48.    (ai_abort "DDTE" "Can't load file AI_UTILS.LSP"))
  49. )
  50.  
  51. (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  52.    (ai_abort "DDTE" nil)        ; a Nil <msg> supresses
  53. )                                    ; ai_abort's alert box dialog.
  54.  
  55. ;;; ==================== end load-time operations ===========================
  56. ;;
  57. ;;The main function...
  58. ;;
  59. (defun C:DDTE
  60.    (
  61.       / _update _previous te_list _next te_done
  62.       te_cancel index te_old sset set_len _undo _build
  63.    )
  64.  
  65.    ;build list of text
  66.    (defun _build (/ tb_index)
  67.       ;preset variables
  68.       (setq tb_index 0)
  69.       ;initialize list
  70.       (setq te_list nil)
  71.       ;build the list
  72.       (while (/= tb_index (sslength sset))
  73.          (if (= te_list nil)
  74.             (setq te_list
  75.                (list
  76.                   (cons tb_index
  77.                      (cdr
  78.                         (assoc 1
  79.                            (entget
  80.                               (ssname sset tb_index)
  81.                            )
  82.                         )
  83.                      )
  84.                   )
  85.                )
  86.             )
  87.             (setq te_list
  88.                (cons
  89.                   (cons tb_index
  90.                      (cdr
  91.                         (assoc 1
  92.                            (entget
  93.                               (ssname sset tb_index)
  94.                            )
  95.                         )
  96.                      )
  97.                   )
  98.                te_list)
  99.             )
  100.          )
  101.          (setq tb_index (1+ tb_index))
  102.       )
  103.    )
  104.  
  105.    ;update the list
  106.    (defun _update ()
  107.       (setq te_list
  108.          (subst
  109.             (cons index
  110.                (get_tile "te")
  111.             )
  112.             (assoc index te_list)
  113.             te_list
  114.          )
  115.       )
  116.    )
  117.  
  118.    ;go to the previous piece of text
  119.    (defun _previous ()
  120.       (_clear)
  121.       (_update)
  122.       (setq index (1- index))
  123.       (set_tile "te" (cdr (assoc index te_list)))
  124.       (if (= index 0)
  125.          (mode_tile "previous" 1)
  126.       )
  127.       (_index)
  128.    )
  129.  
  130.    ;go to the next piece of text
  131.    (defun _next ()
  132.       ;check to see if this is the last
  133.       (if (< (1+ index) sset_len)
  134.          ;go to next piece if not last
  135.          (progn
  136.             (_clear)
  137.             (_update)
  138.             (setq index (1+ index))
  139.             (set_tile "te" (cdr (assoc index te_list)))
  140.             (if (= index (- sset_len 1))
  141.                (mode_tile "next" 1)
  142.             )
  143.          )
  144.          ;leave if they pressed enter on last piece
  145.          (progn
  146.             (_update)
  147.             (setq #te_loc (done_dialog 1))
  148.          )
  149.       )
  150.       (_index)
  151.    )
  152.  
  153.    ;clear the grayed out tiles
  154.    (defun _clear ()
  155.       (if (/= sset_len 1)
  156.          (progn
  157.             (mode_tile "next" 0)
  158.             (mode_tile "previous" 0)
  159.          )
  160.       )
  161.    )
  162.  
  163.    ;pull up the help screen
  164.    (defun _help ()
  165.       (acad_helpdlg "heaven" "ddte")
  166.    )
  167.  
  168.    ;restore current text string
  169.    (defun _undo ()
  170.       (set_tile "te" (cdr (assoc 1 (entget (ssname sset index)))))
  171.       (_update)
  172.    )
  173.  
  174.    ;go back to all of the original text
  175.    (defun _undoall ()
  176.       (_build)
  177.       (set_tile "te" (cdr (assoc index te_list)))
  178.    )
  179.  
  180.    ;convert current string to upper case
  181.    (defun _upper ()
  182.       (set_tile "te" (strcase (get_tile "te")))
  183.       (_update)
  184.    )
  185.  
  186.    ;convert current string to lower case
  187.    (defun _lower ()
  188.       (set_tile "te" (strcase (get_tile "te") T))
  189.       (_update)
  190.    )
  191.  
  192.    (defun _index ()
  193.       (set_tile "error"
  194.          (strcat (itoa (1+ index)) " of " (itoa sset_len))
  195.       )
  196.    )
  197.  
  198.    (setq
  199.       te_cancel nil
  200.       index 0
  201.    )
  202.  
  203.    ;get the selection set
  204.    (if (= sset nil)
  205.       (while (= (setq sset (ssget (list (cons 0 "TEXT")))) nil))
  206.    )
  207.  
  208.    ;set up the original list
  209.    (_build)
  210.  
  211.    ;set up the dialog identification
  212.    (setq id (load_dialog "ddte.dcl"))
  213.    (if
  214.       (setq file
  215.          (open "c:/ddte.loc" "r")
  216.       )
  217.       (progn
  218.          (setq #te_loc
  219.             (list
  220.                (atoi
  221.                   (read-line file)
  222.                )
  223.                (atoi
  224.                   (read-line file)
  225.                )
  226.             )
  227.          )
  228.          (close file)
  229.       )
  230.    )
  231.  
  232.    (new_dialog "ddte" id "" #te_loc)
  233.  
  234.    ;preset variables
  235.    (setq sset_len (sslength sset))
  236.    ;(setq index 0)
  237.  
  238.    ;set up the dialog box
  239.    (set_tile "te" (cdr (assoc 1 (entget (ssname sset index)))))
  240.  
  241.    ;gray out appropriate tiles
  242.    (if (/= sset_len 1)
  243.       (mode_tile "previous" 1)
  244.       (progn
  245.          (mode_tile "previous" 1)
  246.          (mode_tile "next" 1)
  247.          (mode_tile "undoall" 1)
  248.       )
  249.    )
  250.  
  251.    ;tell them where they are
  252.    (_index)
  253.  
  254.    ;setup callbacks
  255.    (action_tile "cancel" "(setq #te_loc (done_dialog 0))")
  256.    (action_tile "accept" "(_update)(setq #te_loc (done_dialog 1))")
  257.    (mapcar
  258.       '(lambda (x)
  259.          (action_tile x (strcat "(_" x ")"))
  260.       )
  261.       (list "help" "undoall" "upper" "lower" "undo" "previous" "next")
  262.    )
  263.  
  264.    ;go until they quit
  265.    (setq te_cancel (start_dialog))
  266.    (unload_dialog id)
  267.  
  268.    (setq file (open "c:/ddte.loc" "w"))
  269.    (write-line (itoa (car #te_loc)) file)
  270.    (write-line (itoa (cadr #te_loc)) file)
  271.    (close file)
  272.  
  273.    ;process the result
  274.    (if (/= te_cancel 0)
  275.       (progn
  276.          ;preset variables
  277.          ;(setq sset_len (sslength sset))
  278.          (setq index 0)
  279.          ;build list of text items
  280.          (while (/= index sset_len)
  281.             (entmod
  282.                (subst
  283.                   (cons 1 (cdr (assoc index te_list)))
  284.                   (assoc 1 (entget (ssname sset index)))
  285.                   (entget (ssname sset index))
  286.                )
  287.             )
  288.             (setq index (1+ index))
  289.          )
  290.       )
  291.    )
  292.    (princ)
  293. )
  294. ;;============================== The End =====================================
  295.